﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SiteFox.Business.Manager
{
    public static class Blog
    {
        public static IList<Model.Blog> GetAll()
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.Blog select c;
            return _Query.ToList();
        }
        public static Model.Blog GetByID(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.Blog where c.ID == _ID select c;
            if (_Query.Count() > 0)
            {
                return _Query.Single();
            }
            else
            {
                return null;
            }
        }
        public static void Create(Model.Blog _Blog)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            _Entities.AddToBlog(_Blog);
            _Entities.SaveChanges();
        }
        public static void Edit(Model.Blog _Blog)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.Blog where c.ID == _Blog.ID select c;
            var __Blog = _Query.Single();
            __Blog.Created = _Blog.Created;
            __Blog.CreatedBy = _Blog.CreatedBy;
            __Blog.Description = _Blog.Description;
            __Blog.Modified = _Blog.Modified;
            __Blog.ModifiedBy = _Blog.ModifiedBy;
            __Blog.Name = _Blog.Name;
            _Entities.SaveChanges();
        }
        public static void Delete(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.Blog where c.ID == _ID select c;
            var _Blog = _Query.Single();
            //var _QuickLinkList = SiteFox.Business.Manager.QuickLink.GetByQuickLinks(_ID);
            //for (int i = 0; i < _QuickLinkList.Count; i++)
            //{
            //    var _QuickLinkListItem = _QuickLinkList[i];
            //    SiteFox.Business.Manager.QuickLink.Delete(_QuickLinkListItem.ID);
            //}
            _Entities.Blog.DeleteObject(_Blog);
            _Entities.SaveChanges();
        }
    }
}
